﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pku.BookStore.Web.Controllers
{
    public class ProductController : Controller
    {
        //
        // GET: /Product/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Detail(int? ID)
        {
            if (ID == null) ID = 0;
            IServices.IProductServices productDal = new Services.ProductServices();
            IServices.ICommentServices commentDal = new Services.CommentServices();

            var bookModel = productDal.GetEntityById(Convert.ToInt32(ID));

            Model.ProductParam productParam = new Model.ProductParam();
            productParam.PageNo = 1;
            productParam.PageRow = 8;
            productParam.isSpecial = -1;
            productParam.CategoryID = bookModel.CategoryID;
            var productList = productDal.Search(productParam);

            Model.CommentParam param = new Model.CommentParam();
            param.PageNo = 1;
            param.PageRow = 10;
            param.BookID = Convert.ToInt32(ID);
            var commentList = commentDal.Search(param);

            IDictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("productList", productList);
            dic.Add("commentList", commentList);
            dic.Add("bookModel", bookModel);

            return View(dic);
        }

        public ActionResult Special(int? p)
        {
            if (p == null) p = 1;
            IServices.IProductServices productDal = new Services.ProductServices();

            #region 新书速递
            Model.ProductParam productParam = new Model.ProductParam();
            productParam.PageNo = 1;
            productParam.PageRow = 8;
            productParam.isSpecial = 0;
            var productListNew = productDal.Search(productParam);
            #endregion

            #region 列表
            productParam.PageNo = Convert.ToInt32(p);
            productParam.PageRow = 10;
            productParam.isSpecial = 1;
            productParam.CategoryIDBig = 0;
            productParam.CategoryID = 0;
            var productList = productDal.Search(productParam);
            ViewBag.productCount = productDal.SearchCount(productParam);
            #endregion

            IDictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("productListNew", productListNew);
            dic.Add("productList", productList);

            return View(dic);
        }

        public ActionResult Top50(int? p)
        {
            if (p == null) p = 1;
            IServices.IProductServices productDal = new Services.ProductServices();

            #region 新书速递
            Model.ProductParam productParam = new Model.ProductParam();
            productParam.PageNo = 1;
            productParam.PageRow = 8;
            productParam.isSpecial = 0;
            var productListNew = productDal.Search(productParam);
            #endregion

            #region 列表
            productParam.PageNo = Convert.ToInt32(p);
            productParam.PageRow = 50;
            productParam.isSpecial = 1;
            productParam.CategoryIDBig = 0;
            productParam.CategoryID = 0;
            var productList = productDal.Search(productParam);
            ViewBag.productCount = productDal.SearchCount(productParam);
            #endregion

            IDictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("productListNew", productListNew);
            dic.Add("productList", productList);

            return View(dic);
        }

        public ActionResult NewBook(int? p)
        {
            if (p == null) p = 1;
            IServices.IProductServices productDal = new Services.ProductServices();

            #region 新书速递
            Model.ProductParam productParam = new Model.ProductParam();
            productParam.PageNo = 1;
            productParam.PageRow = 8;
            productParam.isSpecial = 0;
            var productListNew = productDal.Search(productParam);
            #endregion

            #region 列表
            productParam.PageNo = Convert.ToInt32(p);
            productParam.PageRow = 10;
            productParam.isSpecial = -1;
            productParam.CategoryIDBig = 0;
            productParam.CategoryID = 0;
            var productList = productDal.Search(productParam);
            ViewBag.productCount = productDal.SearchCount(productParam);
            #endregion

            IDictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("productListNew", productListNew);
            dic.Add("productList", productList);

            return View(dic);
        }
    }
}
